import os
from dotenv import load_dotenv

# 加载 .env 文件中的环境变量
load_dotenv()

# API Keys
TAVILY_API_KEY = os.getenv("TAVILY_API_KEY")
DEEPSEEK_API_KEY = os.getenv("DEEPSEEK_API_KEY")

# Data Source & Storage
SEARCH_QUERY = os.getenv("SEARCH_QUERY", "有关langchain的知识点")
MAX_SEARCH_RESULTS = int(os.getenv("MAX_SEARCH_RESULTS", 20))
OUTPUT_DIR = os.getenv("OUTPUT_DIR", "extracted_documents")

# MongoDB Configuration
MONGO_URI = os.getenv("MONGO_URI", "mongodb://localhost:27017")
MONGO_DB_NAME = os.getenv("MONGO_DB_NAME", "llamaindex-2")

# PostgreSQL Configuration
PG_HOST = os.getenv("PG_HOST", "localhost")
PG_PORT = int(os.getenv("PG_PORT", 5433))
PG_USER = os.getenv("PG_USER", "postgres")
PG_PASSWORD = os.getenv("PG_PASSWORD", "password")
PG_DB_NAME = os.getenv("PG_DB_NAME", "vector_db")
PG_TABLE_NAME = os.getenv("PG_TABLE_NAME", "llamaindex-2")

# Redis Configuration
REDIS_HOST = os.getenv("REDIS_HOST", "127.0.0.1")
REDIS_PORT = int(os.getenv("REDIS_PORT", 6379))
REDIS_CACHE_COLLECTION = os.getenv("REDIS_CACHE_COLLECTION", "my_test_cache")

# Models Configuration
EMBED_MODEL_PATH = os.getenv("EMBED_MODEL_PATH")
EMBED_DIM = int(os.getenv("EMBED_DIM", 384))
LLM_MODEL_NAME = os.getenv("LLM_MODEL_NAME", "deepseek-chat")

# Pipeline Configuration
CHUNK_SIZE = int(os.getenv("CHUNK_SIZE", 512))
CHUNK_OVERLAP = int(os.getenv("CHUNK_OVERLAP", 20))
NUM_WORKERS = int(os.getenv("NUM_WORKERS", 4))

# 校验关键配置是否存在
if not all([TAVILY_API_KEY, DEEPSEEK_API_KEY, EMBED_MODEL_PATH]):
    raise ValueError("关键的 API 密钥或模型路径未在 .env 文件中设置！")